package BankSimulation;

public class Account {
    private String accountNumber;
    private String accountName;
    private double balance=0;

    public Account(String accountNumber, String accountName, double balance) {
        this.accountNumber = accountNumber;
        this.accountName = accountName;
        if(balance>=0) {
            this.balance = balance;
        }
    }


    public void deposit(double amount) {
        if(amount>0) {
            balance+=amount;
            System.out.println("存款成功！成功存入 "+amount+" 元，余额为："+balance);
        }else{
            System.out.println("错误的存款金额");
        }
    }

    public void withdraw(double amount) {
        if(amount>0) {
            if(amount<=balance) {
                balance-=amount;
                System.out.println("取款成功！成功取出 "+amount+" 元，余额为："+balance);
            }else{
                System.out.println("取款失败！余额不足");
            }
        }else{
            System.out.println("错误的取款金额");
        }
    }

    //重写toString方法，打印账户信息
    @Override
    public String toString() {
        return "账号："+accountNumber+" 账户名："+accountName+" 余额："+balance;
    }

}
